package com.lizheng.controller;

import com.lizheng.domain.ResponseResult;
import com.lizheng.domain.entity.Article;
import com.lizheng.service.ArticleService;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/article")
@AllArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "文章控制层")
public class ArticleController {


    private final ArticleService articleService;


//    @GetMapping("/list")
//    public List<Article> test(){
//        return articleService.list();
//    }

    @GetMapping("/hotArticleList")
    public ResponseResult hotArticleList(){
        //查询热门文章 封装成ResponseResult返回
        return articleService.hotArticleList();
    }

    @GetMapping("/articleList")
    public ResponseResult articleList(Long categoryId,Integer pageNum,Integer pageSize){
        return articleService.articleList(categoryId,pageNum,pageSize);
    }

    @GetMapping("/{id}")
    public ResponseResult getArticeDetail(@PathVariable("id") Long id){
        return articleService.getArticeDetail(id);
    }

    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable("id") Long id){
        return articleService.updateViewCount(id);
    }

}
